<!DOCTYPE html>
<html>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <head>promise 测试</head>
    <body> 
        <script>
            var promise = new Promise((resolve, reject)=> {
                resolve(100)
            })
            var p1 = promise.then((value)=> {
                console.log(value)
            })
            function p2 () {
                return new Promise(function(resolve, reject) {
                    resolve('p2')
                })
            }
            p1.then(()=> {}, reason=> {
                console.log(reason)
            })
            Promise.reject(p2()).then(value=> {
                console.log(111)
                console.log(value)
            },reason=> {
                console.log(222)
                console.log(reason)
            })
        
            Promise.race([
                new Promise((resolve, reject) => { setTimeout(() => { resolve(100) }, 1000) }),
                undefined,
                new Promise((resolve, reject) => { setTimeout(() => { reject(100) }, 100) })
                ]).then((data) => {
                    console.log('success ', data);
                }, (err) => {
                    console.log('err ',err);
                });

            Promise.race([
                new Promise((resolve, reject) => { setTimeout(() => { resolve(100) }, 1000) }),
                new Promise((resolve, reject) => { setTimeout(() => { resolve(200) }, 200) }),
                new Promise((resolve, reject) => { setTimeout(() => { reject(100) }, 100) })
            ]).then((data) => {
                console.log('success ', data);
            }, (err) => {
                console.log('err ',err);
            });
            Promise.race([]).then((data) => {
                console.log('success ', data);
            }, (err) => {
                console.log('err ',err);
            });
        </script>
    </body>
</html>